package com.gump.essay.juc;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @auther zzc
 * @date 2021 04 18
 */
public class demo {

    //volatile保证可见性
    public static void main(String[] args) {

        Data data = new Data();

        new Thread(() -> {
            System.out.println("线程1===a=" + data.a);
            try {
                Thread.sleep(3000);
                data.add();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        while (data.a == 0) {
        }
        System.out.println("我是main");
    }

    static class Data {
        volatile int a = 0;

        private void add() {
            this.a = 60;
        }

        //原子类
        AtomicInteger atomicInteger = new AtomicInteger();

        public void atomic(){
            atomicInteger.getAndIncrement();
        }


    }
}
